//
//  JYJMusicPlayerView.m
//  HappyListen
//
//  Created by 冀永金 on 16/9/6.
//  Copyright © 2016年 冀永金. All rights reserved.
//

#import "JYJMusicPlayerView.h"
#import "Masonry.h"
#import "JYJTAMacro.h"
@implementation JYJMusicPlayerView
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self configSubViews];
        self.userInteractionEnabled = YES;
      
    }
    return self;
}
- (void)configSubViews {
    self.bigBackImage = [[UIImageView alloc]initWithFrame:self.bounds];
    [self addSubview:_bigBackImage];
    self.bigBackImage.userInteractionEnabled = YES;
    UIView *blackView = [[UIView alloc]initWithFrame:self.bounds];
    [self.bigBackImage addSubview:blackView];
    blackView.userInteractionEnabled = YES;
    blackView.backgroundColor = [UIColor blackColor];
    blackView.alpha = 0.5;
    self.buttonBackImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"playbar"]];
    self.buttonBackImage.userInteractionEnabled = YES;
    [self.bigBackImage addSubview:_buttonBackImage];
    [self.buttonBackImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).with.offset(0);
        make.bottom.equalTo(self.mas_bottom).with.offset(-120);
        make.width.mas_offset (SCREEN_WIDTH / 3 + 10);
        make.height.mas_offset (SCREEN_HEIGHT / 2 - 50);
    }];
   
    
    self.pauseButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:_pauseButton];
    [self.pauseButton setImage:[UIImage imageNamed:@"pause_img"] forState:UIControlStateNormal];
    [self.pauseButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.buttonBackImage.mas_top).with.offset(81);
        make.left.equalTo(self.buttonBackImage.mas_left).with.offset(34);
        make.height.mas_equalTo(30);
        make.width.mas_equalTo(30);
    }];
    [_pauseButton addTarget:self action:@selector(handlePause:) forControlEvents:UIControlEventTouchUpInside];
    self.lastButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:_lastButton];
    [_lastButton setImage:[UIImage imageNamed:@"before"] forState:UIControlStateNormal];
    [self.lastButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.buttonBackImage.mas_top).with.offset(25);
        make.left.equalTo(self.buttonBackImage.mas_left).with.offset(35);
        make.height.mas_equalTo(25);
        make.width.mas_equalTo(25);

    }];
    [_lastButton addTarget:self action:@selector(handleLastSong:) forControlEvents:UIControlEventTouchUpInside];
    self.nextButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:_nextButton];
    [_nextButton setImage:[UIImage imageNamed:@"next"] forState:UIControlStateNormal];
    [self.nextButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.buttonBackImage.mas_top).with.offset(145);
        make.left.equalTo(self.buttonBackImage.mas_left).with.offset(35);
        make.height.mas_equalTo(25);
        make.width.mas_equalTo(25);
        
    }];
    [_nextButton addTarget:self action:@selector(handleNextSong:) forControlEvents:UIControlEventTouchUpInside];
    self.progressTimeLabel = [[UILabel alloc]init];
    [self addSubview:_progressTimeLabel];
    self.progressTimeLabel.font = [UIFont systemFontOfSize:13];
    self.progressTimeLabel.textColor = [UIColor colorWithRed:0.88 green:0.13 blue:0.11 alpha:1.00];
    [self.progressTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.buttonBackImage.mas_top).with.offset(80);
        make.left.equalTo(self.mas_left).with.offset(75);
        make.width.mas_equalTo(45);
        make.height.mas_equalTo(15);
    }];
    self.totalTimeLabel = [[UILabel alloc]init];
    [self addSubview:_totalTimeLabel];
    self.totalTimeLabel.textColor = [UIColor lightGrayColor];
    self.totalTimeLabel.font = [UIFont systemFontOfSize:13];
    [self.totalTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.buttonBackImage.mas_top).with.offset(100);
        make.left.equalTo(self.mas_left).with.offset(75);
        make.width.mas_equalTo(45);
        make.height.mas_equalTo(15);
    }];
    self.sliderBackImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"AA"]];
    self.sliderBackImage.userInteractionEnabled = YES;
    self.sliderBackImage.frame = CGRectMake(self.buttonBackImage.frame.size.width + 30, SCREEN_HEIGHT / 2 - 30, SCREEN_WIDTH - self.buttonBackImage.frame.size.width - 30, 100);
    [self addSubview:_sliderBackImage];
    self.slider = [[UISlider alloc]init];
    self.slider.maximumValue = 1;
    self.slider.frame = CGRectMake(self.buttonBackImage.frame.size.width + 28, SCREEN_HEIGHT / 2 + 25, self.sliderBackImage.frame.size.width, 10);
    [self addSubview:_slider];
    UIImage *leftSliderImage = [UIImage imageNamed:@"ball"];
    self.slider.minimumTrackTintColor = [UIColor colorWithRed:0.97 green:0.20 blue:0.33 alpha:1.00];
    [self.slider setThumbImage:leftSliderImage forState:UIControlStateNormal];
    [self.slider addTarget:self action:@selector(handleValue:) forControlEvents:UIControlEventValueChanged];

    self.sliderBackImageTwo = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"BB"]];
    self.sliderBackImageTwo.frame = self.sliderBackImage.bounds;
    self.sliderBackImageTwo.userInteractionEnabled = YES;
    self.sliderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 0, 100)];
    self.sliderView.userInteractionEnabled = YES;
    [self.sliderBackImage addSubview:_sliderView];
    [self.sliderView addSubview:_sliderBackImageTwo];
    self.sliderView.clipsToBounds = YES;
    
    self.buttonOfMenu = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:_buttonOfMenu];
    [self.buttonOfMenu setImage:[UIImage imageNamed:@"player_menu_list"] forState:UIControlStateNormal];
    [self.buttonOfMenu mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.buttonBackImage.mas_right).with.offset(10);
        make.bottom.equalTo(self.mas_bottom).with.offset(-130);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(60);
    }];
    [self.buttonOfMenu addTarget:self action:@selector(handleMenu:) forControlEvents:UIControlEventTouchUpInside];
    
    self.buttonOfsupport = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:_buttonOfsupport];
    [self.buttonOfsupport setImage:[UIImage imageNamed:@"player_menu_zan_0"] forState:UIControlStateNormal];
    [self.buttonOfsupport mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.buttonOfMenu.mas_right).with.offset(15);
        make.bottom.equalTo(self.mas_bottom).with.offset(-155);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(60);
    }];
    [self.buttonOfsupport addTarget:self action:@selector(handleSupport:) forControlEvents:UIControlEventTouchUpInside];
    self.buttonOfDownLoad = [UIButton buttonWithType:UIButtonTypeCustom];
    [self addSubview:_buttonOfDownLoad];
    [self.buttonOfDownLoad setImage:[UIImage imageNamed:@"player_menu_down_0"] forState:UIControlStateNormal];
    [self.buttonOfDownLoad mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.buttonOfsupport.mas_right).with.offset(15);
        make.bottom.equalTo(self.mas_bottom).with.offset(-130);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(60);
    }];
    [self.buttonOfDownLoad addTarget:self action:@selector(handleDownLoad:) forControlEvents:UIControlEventTouchUpInside];
    self.buttonOfCollect = [UIButton buttonWithType:UIButtonTypeCustom];
}
- (void)menu:(blockAction)handleMenu support:(blockAction)support cancleSuppot:(blockAction)cancleSuppot downLoad:(blockAction)downLoad  {
    self.handleMenu = handleMenu;
    self.handleSupport = support;
    self.handleCancleSupport = cancleSuppot;
    self.handleDownLoad = downLoad;

}
- (void)pause:(Block)pause lastSong:(Block)lastSong nextSong:(Block)nextSong {
    self.handlePause = pause;
    self.handleLastSong = lastSong;
    self.handleNextSong = nextSong;
}
#pragma mark------暂停 播放
- (void)handlePause:(UIButton *)button {

    self.handlePause(button);
}
#pragma mark-----上一曲
- (void)handleLastSong:(UIButton *)button {
    self.handleLastSong(button);
}
#pragma mark-------下一曲
- (void)handleNextSong:(UIButton *)button {
    self.handleNextSong(button);
}
#pragma mark------slider
- (void)slider:(block)slider {
    self.handleSlider = slider;
}
- (void)handleValue:(UISlider *)slider {
   
    self.handleSlider(slider);
}
#pragma mark----菜单
- (void)handleMenu:(UIButton *)button {
    self.handleMenu(button);
}
#pragma mark-----点赞
- (void)handleSupport:(UIButton *)button {
    [self.buttonOfsupport setImage:[UIImage imageNamed:@"player_menu_zan_1"] forState:UIControlStateNormal];
    [self.buttonOfsupport removeTarget:self action:@selector(handleSupport:) forControlEvents:UIControlEventTouchUpInside];
    [self.buttonOfsupport addTarget:self action:@selector(handleCancleSupport:) forControlEvents:UIControlEventTouchUpInside];
    self.handleSupport(button);
}
- (void)handleCancleSupport:(UIButton *)button {
    
    [self.buttonOfsupport setImage:[UIImage imageNamed:@"player_menu_zan_0"] forState:UIControlStateNormal];
    [self.buttonOfsupport removeTarget:self action:@selector(handleCancleSupport:) forControlEvents:UIControlEventTouchUpInside];
    [self.buttonOfsupport addTarget:self action:@selector(handleSupport:) forControlEvents:UIControlEventTouchUpInside];
    self.handleCancleSupport(button);
}
- (void)handleDownLoad:(UIButton *)button {
    self.handleDownLoad(button);
}
//- (void)handleCollect:(UIButton *)button {
//    [self.buttonOfCollect setImage:[UIImage imageNamed:@"player_menu_save_1"] forState:UIControlStateNormal];
//    [self.buttonOfCollect removeTarget:self action:@selector(handleCollect:) forControlEvents:UIControlEventTouchUpInside];
//    [self.buttonOfCollect addTarget:self action:@selector(handleCancleCollect:) forControlEvents:UIControlEventTouchUpInside];
//    self.handleCollect(button);
//}
//- (void)handleCancleCollect:(UIButton *)button {
//    [self.buttonOfCollect removeTarget:self action:@selector(handleCancleCollect:) forControlEvents:UIControlEventTouchUpInside];
//    [self.buttonOfCollect setImage:[UIImage imageNamed:@"player_menu_save_0"] forState:UIControlStateNormal];
//    [self.buttonOfCollect addTarget:self action:@selector(handleCollect:) forControlEvents:UIControlEventTouchUpInside];
//    self.handleCancleCollect(button);
//
//}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
